package com.sxran.im.handler;

import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.sxran.im.bean.NotificationBody;
import com.sxran.im.info.ImGroup;
import com.sxran.im.info.ImUser;
import com.sxran.im.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class WebrtcOfferCmdHandler extends AbstractCmdHandler<ImUser>{

    private Logger logger = LoggerFactory.getLogger(WebrtcOfferCmdHandler.class);

    @Resource
    private UserService userService;

    @Value("${srs.ip}")
    private String webRTCIp;

    @Override
    public Object doBeanService(ImUser bean) {
        String sdp = null;
        String toUid = null;

        String webRTCURL = "http://"+webRTCIp+":1985/rtc/v1/play/";
        Map<String,String> req = new HashMap<>();
        req.put("api",webRTCURL);
        req.put("streamurl","webRTC://"+webRTCIp+"/live/1");
        req.put("sdp",sdp);
        String post = HttpUtil.post(webRTCURL, JSONUtil.toJsonStr(req));
        // 通知
        NotificationBody notificationBody = new NotificationBody();
        notificationBody.setTargetList(new String[]{
                toUid
        });
        notificationBody.setContent(post);
        return notificationBody;
    }

    public static void main(String[] args) {
        Map<String,String> req = new HashMap<>();
        req.put("11","22");
        req.put("22","22");
        System.out.println(req.toString());
    }
}
